SMS.controller('SettingsController',
function SettingsController($scope, utils, globals, notifications)
{
    $scope.settings = globals.settings;
    $scope.Timeouts = [
        { id: 10000, name: 10 },
        { id: 20000, name: 20 },
        { id: 30000, name: 30 },
        { id: 40000, name: 40 },
        { id: 50000, name: 50 },
        { id: 60000, name: 60 },
        { id: 90000, name: 90 },
        { id: 120000, name: 120 }
    ];
    $scope.Protocols = ["json", "jsonp"];
    $scope.LibraryLayouts = [
        { id: "list", name: "List" },
        { id: "grid", name: "Grid" },
    ];
    $scope.DefaultLibraryLayout = 'grid';
    $scope.$watch('settings.HideAZ', function () {
        if (globals.settings.HideAZ) {
            $('#AZIndex').hide();
        } else {
            $('#AZIndex').show();
        }
    });
    $scope.save = function () {
        if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); }
        if (globals.settings.NotificationTrack) {
            notifications.requestPermissionIfRequired();
            if (!notifications.hasNotificationPermission()) {
                alert('HTML5 Notifications are not available for your current browser, Sorry :(');
            }
        }
        if (globals.settings.NotificationNowPlaying) {
            notifications.requestPermissionIfRequired();
            if (!notifications.hasNotificationPermission()) {
                alert('HTML5 Notifications are not available for your current browser, Sorry :(');
            }
        }
        if (globals.settings.SaveTrackPosition) {
            //saveTrackPosition();
        } else {
            //deleteCurrentPlaylist();
        }

        utils.setValue('Settings', $scope.settings, true);
        notifications.updateMessage('Settings Updated!', true);
        $scope.loadSettings();
        if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') {
            $scope.ping();
        }
    };

    /* Load on Startup */
    /* End Startup */
});
